<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :md="8" :sm="12">
            <a-form-item label="选择产品">
              <a-select
                ref="select"
                placeholder="请选择需要装箱的产品"
                v-model="queryParam.productID"
              >
                <a-select-option :label="item.productName" v-for="(item,key) in productList" :key="item.id"
                                 :value="item.id">
                  {{ item.productName }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :md="8" :sm="12">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--<a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>-->
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <!--<div class="table-operator" style="border-top: 5px">-->
    <!--<a-button @click="handleAdd" type="primary" icon="plus">添加用户</a-button>
    <a-button type="primary" icon="download" @click="handleExportXls('用户信息')">导出</a-button>
    <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
              @change="handleImportExcel">
      <a-button type="primary" icon="import">导入</a-button>
    </a-upload>
    <a-button type="primary" icon="hdd" @click="recycleBinVisible=true">回收站</a-button>-->
    <!--<a-dropdown v-if="selectedRowKeys.length > 0">
      <a-menu slot="overlay" @click="handleMenuClick">
        <a-menu-item key="1">
          <a-icon type="delete" @click="batchDel"/>
          删除
        </a-menu-item>
        <a-menu-item key="2">
          <a-icon type="lock" @click="batchFrozen('2')"/>
          冻结
        </a-menu-item>
        <a-menu-item key="3">
          <a-icon type="unlock" @click="batchFrozen('1')"/>
          解冻
        </a-menu-item>
      </a-menu>
      <a-button style="margin-left: 8px">
        批量操作
        <a-icon type="down"/>
      </a-button>
    </a-dropdown>-->
    <!--</div>-->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a style="font-weight: 600">{{
          selectedRowKeys.length
        }}</a>项&nbsp;&nbsp;
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        bordered
        size="middle"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.avatar)" icon="user"/>
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
         <!-- <a @click="handleEdit(record)" v-has="'user:edit'">编辑</a>-->
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical"/>

          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;" @click="handleDetail(record)">详情</a>
              </a-menu-item>

              <a-menu-item>
                <a href="javascript:;" @click="handleChangePassword(record.username)">密码</a>
              </a-menu-item>

              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>

              <a-menu-item v-if="record.status==1">
                <a-popconfirm title="确定冻结吗?" @confirm="() => handleFrozen(record.id,2,record.username)">
                  <a>冻结</a>
                </a-popconfirm>
              </a-menu-item>

              <a-menu-item v-if="record.status==2">
                <a-popconfirm title="确定解冻吗?" @confirm="() => handleFrozen(record.id,1,record.username)">
                  <a>解冻</a>
                </a-popconfirm>
              </a-menu-item>

              <a-menu-item>
                <a href="javascript:;" @click="handleAgentSettings(record.username)">代理人</a>
              </a-menu-item>

            </a-menu>
          </a-dropdown>
        </span>


      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">

        <a-row :gutter="24">
          <a-col :md="6" :sm="12">
            <a-form-item label="装箱单名称">
              <a-input placeholder="请输入装箱单名称" v-model="boxName"></a-input>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row :gutter="24">
          <a-col :md="6" :sm="12">
            <a-form-item label="备注">
              <a-textarea
                v-model="remark"
                placeholder="请输入备注"
                :auto-size="{ minRows: 2, maxRows: 5 }"
              />
            </a-form-item>
          </a-col>
        </a-row>

        <a-row :gutter="24">
          <a-col :md="6" :sm="12">
            <a-form-item>
              <a-button @click="saveBox" type="primary">保存提交</a-button>
              <a-button @click="$router.go(-1)" style="margin-left: 10px">返回</a-button>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 表单区域 end-->
  </a-card>
</template>

<script>
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import JInput from '@/components/jeecg/JInput'
import {getAction} from "../../api/manage";
import Qs from 'qs'

export default {
  name: "UserList",
  mixins: [JeecgListMixin],
  components: {
    JInput,
  },
  data() {
    return {
      description: '这是新增装箱单',
      boxName: '', // 装箱单名称
      remark: '', // 备注
      queryParam: {},
      recycleBinVisible: false,
      productList: [], // 产品列表
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '员工姓名',
          align: "center",
          dataIndex: 'customerName',
          width: 120,
          sorter: true
        },
        {
          title: '员工性别',
          align: "center",
          width: 80,
          dataIndex: 'sex',
          customRender: function (text) {
            if (text == 1) {
              return '男'
            } else {
              return '女'
            }
          },
          sorter: true
        },
        {
          title: '员工编号',
          align: "center",
          width: 100,
          dataIndex: 'customerCode'
        },
        {
          title: '部门',
          align: "center",
          width: 100,
          dataIndex: 'departName'
        },
        {
          title: '小产品编号',
          align: "center",
          width: 100,
          dataIndex: 'code'
        },
        {
          title: '产品名称',
          align: "center",
          width: 100,
          dataIndex: 'productName'
        }
      ],
      url: {
        list: "/orderCenter/listNotshipments?orderSn=" + this.$route.query.order, // 未发货人员列表
        getProductByBatchID: "/orderCenter/getProductByBatchID", // 可选择的产品列表
        saveBox: "/orderCenter/saveBox", // 新增装箱单，并添加所选的小产品
      },
    }
  },
  computed: {
    /*importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }*/
  },
  created() {
    this.getProducyList()
  },
  methods: {

    mytest() {
      console.log(this.selectedRowKeys)
    },

    /**
     * 添加装箱单
     */
    saveBox() {
      if (this.remark == '' || this.boxName == '') {
        this.$message.warning("请填写完整信息")
        return
      } else {
        getAction(this.url.saveBox, {
          'batchID': this.$route.query.batch,
          'packingName': this.boxName,
          'remark': this.remark,
          'productID': this.selectedRowKeys.toString()
        }).then(res => {
          if (res.code == '0') {
            // this.$router.go(-1)
            this.loadData()
            this.$message.success("添加成功")
            this.boxName = ''
            this.remark = ''
          } else {
            this.$message.error("添加失败")
          }
        })
      }
    },

    /**
     * 获取产品列表
     */
    getProducyList() {
      getAction(this.url.getProductByBatchID, {
        'batchID': this.$route.query.batch
      }).then(res => {
        if (res.code == '0') {
          this.productList = res.data
        }
      })
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less'
</style>